Skip to main content

All Questions

0votes
5answers
247views

The cases where returning Bools as literal expressions is a better option

Most people would return Bools as follows: bananas(color) { return (color = "yellow") } and not as literal expressions; that is, not this way: bananas(color) { if (color = "...
john c. j.'s user avatar
0votes
2answers
110views

Negation of sameness is confirmation of difference [closed]

De Morgan's laws: the negation of a disjunction is the conjunction of the negations; and the negation of a conjunction is the disjunction of the negations; or, the same: not (A or B) = not A and not B;...
john c. j.'s user avatar
10votes
5answers
752views

If-else ladder that is supposed to catch all conditions - should a redundant final clause be added?

This is a thing I'm doing a lot lately. Example: setCircle(circle, i, { current }) { if (i == current) { circle.src = 'images/25CE.svg' circle.alt = 'Now picking' } else if (...
gaazkam's user avatar
  • 4,519
2votes
1answer
293views

Guard block moved to the bottom [closed]

Sometimes it is a good idea to have a guard block: https://softwareengineering.stackexchange.com/a/157413 https://en.wikipedia.org/wiki/Guard_(computer_science) Guard block guards against special ...
john c. j.'s user avatar
75votes
10answers
30kviews

Is it good practice to replace division with multiplication when possible?

Whenever I need division, for example, condition checking, I would like to refactor the expression of division into multiplication, for example: Original version: if(newValue / oldValue >= ...
ocomfd's user avatar
  • 5,750
2votes
2answers
655views

Get value from UI element or from variable

I had a debate with a friend and I'm looking for a way to resolve it and decide which approach is better for maintenance and whether there's some consensus about a best practice regarding it: If an ...
BornToCode's user avatar
11votes
6answers
1kviews

What to return if something failed, rather than doing something 'random'? [duplicate]

Say I re-implement a method for finding the position of a string within a string. So I get either the position which is an integer, or a "magic number" like -1. I see this pattern in so many ...
anemaria20's user avatar
21votes
5answers
3kviews

Should non-trivial conditional statements be moved to the initialization section of loops?

I got this idea from this question on stackoverflow.com The following pattern is common: final x = 10;//whatever constant value for(int i = 0; i < Math.floor(Math.sqrt(x)) + 1; i++) { //...do ...
Celeritas's user avatar
0votes
0answers
40views

Functions inside conditionals [duplicate]

Is it a poor idea for readability or maintainability to use functions in conditionals as in the following example? if (move_uploaded_file($file['tmp_name'], $destinationFile)) { // Do work } ...
Goose's user avatar
  • 1,908
0votes
3answers
151views

Handling source code table alignment

Sometimes there is need to have tables (big or small) in source code. ItemType const SomeTable[] = { // id name min max ITEM( 3, "Foo", 70, 180), ITEM(13, "Bar", 30, 50), ITEM(...
user694733's user avatar
-2votes
2answers
7kviews

How to really understand programming? [duplicate]

I have started to learn to program. I am interested in it and dont mind how long it takes to learn. But I am using books to start out and I find that there are some things I get and some things I have ...
user121582's user avatar
15votes
3answers
957views

Does usage of advanced language features decrease maintainability? [duplicate]

On a code review, I've stumbled on an interesting idea, which I can't properly judge alone. Is it OK to improve readability of code by means of not widely known language syntax? When the original ...
ulidtko's user avatar
5votes
4answers
14kviews

How can I stop myself overwriting member variables with 'new' ones?

The bulk of my programming experience has been with C++ and (shudder) FORTRAN (I'm a scientist not a programmer as such, but I do my best). I've recently started using python extensively and find it ...
Bogdanovist's user avatar
26votes
11answers
2kviews

Maintenance wise, is `else while` without intervening braces considered safe?

Is else while without intervening braces considered "safe" maintenance wise? Writing if-else code without braces like below... if (blah) foo(); else bar(); ...carries a risk because the lack ...
user541686's user avatar
140votes
18answers
53kviews

Is there an excuse for short variable names?

This has become a large frustration with the codebase I'm currently working in; many of our variable names are short and undescriptive. I'm the only developer left on the project, and there isn't ...

153050per page
close